package com.source.module_kotlin_library.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.source.module_kotlin_library.R
import com.source.module_kotlin_library.utils.KTToastUtils
import kotlinx.android.synthetic.main.activity_kt_login.*

class KTLoginActivity : AppCompatActivity() {
    companion object {
        fun startActivity(context: Context) {
            var intent = Intent()
            intent.setClass(context, KTLoginActivity::class.java)
            context.startActivity(intent)
        }
    }

    lateinit var context: Context
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_kt_login)
        initView()
        initListener()
    }

    /**
     * 初始化控件
     */
    fun initView() {
        context = this
        btnLogin.text = "Login"

    }

    /**
     * 注册监听
     */
    fun initListener() {
        tvGetVerify.setOnClickListener {
            val phoneNumber = etPhoneNumber.text.toString()
            if (phoneNumber.isNullOrEmpty()) {
                KTToastUtils.showToast(this, "请输入手机号")
                return@setOnClickListener
            }
            KTToastUtils.showToast(this@KTLoginActivity, "手机号：${phoneNumber}${tvGetVerify.text.toString()}成功")
        }

        btnLogin.setOnClickListener {
            val verifyCode = etVerifyCode.text.toString()
            if (verifyCode.isNullOrEmpty()) {
                KTToastUtils.showToast(this@KTLoginActivity, "请输入验证码")
                return@setOnClickListener
            }
            KTToastUtils.showToast(this@KTLoginActivity, "verifyCode：${verifyCode}")
            KTMainActivity.startActivity(this)
        }

    }
}